using System;
using NUnit.Framework;
using OpenWaves.Caching;

namespace OpenWaves.UnitTests.Caching
{
    [TestFixture]
    public class MultilevelCacheTests
    {
        [Test]
        public void GIVEN_value_exists_in_2nd_level_cache_but_not_in_1st_level_cache_WHEN_value_is_retrieved_THEN_1st_level_cache_is_populated()
        {
            var expecetdValue = new object();

            var firstLevelCache = new DictionaryCache<MultilevelCacheEntry<object>>();
            var secondLevelCache = new DictionaryCache<MultilevelCacheEntry<object>>();
            secondLevelCache.InsertValue("key", new MultilevelCacheEntry<object>(expecetdValue, DateTime.MaxValue), DateTime.MaxValue);

            var cache = new MultilevelCache<object>(firstLevelCache, secondLevelCache);

            cache.GetValue("key");

            Assert.That(firstLevelCache.GetValue("key").Value, Is.SameAs(expecetdValue));
        }
    }
}